package fi.libros.dao;

import com.google.appengine.api.datastore.Entity;

import fi.libros.domain.Book;
import fi.libros.gae.EntityMapper;


public class BookMapper implements EntityMapper<Book> {
	private static final String KIND_BOOK = "book";
	private static final String PROP_ISBN = "isbn";
	private static final String PROP_TITLE = "title";
	private static final String PROP_AUTHOR = "author";
	private static final String PROP_PUBLISHER = "publisher";

	@Override
	public Entity mapToEntity(Book book) {
		Entity e = new Entity(KIND_BOOK);
		e.setProperty(PROP_ISBN, book.getIsbn());
		e.setProperty(PROP_TITLE, book.getTitle());
		e.setProperty(PROP_AUTHOR, book.getAuthor());
		e.setProperty(PROP_PUBLISHER, book.getPublisher());
		return e;
	}

	@Override
	public Book mapFromEntity(Entity e) {
		Book book = new Book();
		book.setIsbn((String)e.getProperty(PROP_ISBN));
		book.setTitle((String)e.getProperty(PROP_TITLE));
		book.setAuthor((String)e.getProperty(PROP_AUTHOR));
		book.setPublisher((String)e.getProperty(PROP_PUBLISHER));
		return book;
	}
}

